---
title: "Information_Credibility_20190919"
output:
  html_document:
    df_print: paged
  pdf_document: default
  word_document: default
---

## R Markdown

Include packages

```{r}
library(DBI)
library(RPostgreSQL)
library(glmmML)
library(ivtools)
library(ivpack)
library(ivmodel)
library(ivprobit)
library(lfe)
library(DirectEffects)
library(AER)
library(rdd)
library(rddtools)
library(stargazer)
library(ggplot2)

rm(list=ls())

setwd("/Users/charleschang/Dropbox/Google_RS/r_political_netizens/dataverse")

```


## load data
```{r}
## Main result: Kunming railway station attack data
load("alldata.RData")
load("h24data.RData")
load("h2data.RData")
load("h05data.RData")

##Placebo: Guangzhou railway station attack data
load("alldatagz.RData")
load("data24hgz.RData")
load("data2hgz.RData")
load("data05hgz.RData")

```


## Hypothesis 1 - Table 1

```{r}

hallv1 <- clogit(political ~ credinfo + dlapse + credcontrol + crednation + strata(uid), data = alldata)
summary(hallv1)

# user clustered re
stargazer(hallv1, type = "text",
          cstar.cutoffs = c(0.05, 0.01, 0.001),
          covariate.labels = c("Government information","Days passed","Assertion of control","Sensational stories"),
          dep.var.labels   = "Political Post, binary",
          out = "Table 1.txt")

```


## Hypothesis 2 -- Table 2
```{r}

ivhall <- ivreg(dist2krs ~ credinfo | dlapse, data=alldata)
summary(ivhall, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivhall, alldata$uid)

ivh24v1 <- ivreg(dist2krs ~ credinfo | dlapse, data=h24data)
summary(ivh24v1, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24v1, h24data$uid)

ivh2v1 <- ivreg(dist2krs ~ credinfo | dlapse, data=h2data)
summary(ivh2v1, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh2v1, h2data$uid)

ivh05v1 <- ivreg(dist2krs ~ credinfo | dlapse, data=h05data)
summary(ivh05v1, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh05v1, h05data$uid)

```


## Placebo Test -- Table 3
```{r}
ivh21 <- ivreg(dist2krs ~ credinfo | dlapse, data=alldatagz)
summary(ivh21, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh21, alldatagz$uid)

ivh22 <- ivreg(dist2krs ~ credinfo | dlapse, data=data24hgz)
summary(ivh22, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh22, data24hgz$uid)

ivh24 <- ivreg(dist2krs ~ credinfo | dlapse, data=data2hgz)
summary(ivh24, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24, data2hgz$uid)

ivh25 <- ivreg(dist2krs ~ credinfo | dlapse, data=data05hgz)
summary(ivh25, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh25, data05hgz$uid) 
```

## Descriptive analysis
```{r}
stargazer(alldata, type = "text", title="Descriptive statistics", digits=1, out="tableA6.txt")

stargazer(h24data, type = "text", title="Descriptive statistics", digits=1, out="tableA7.txt")

stargazer(h2data, type = "text", title="Descriptive statistics", digits=1, out="tableA8.txt")

stargazer(h05data, type = "text", title="Descriptive statistics", digits=1, out="tableA9.txt")
```



## Continuity of subsets of samples near press releases -- Table A.10
```{r}
sa1 <- glm(npost ~ credinfo, data = h24data)
summary(sa1)

sa2 <- glm(follower~ credinfo, data = h24data)
summary(sa2)

sa3 <- glm(following ~ credinfo, data = h24data)
summary(sa3)

stargazer(sa1, sa2, sa3, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          # title = "Information credibility",
          covariate.labels = c("Government information",  "Constant"),
          dep.var.labels   = c("Number of user's post", "Number of followers", "Number of following" )
          )

```

## regression with political posts -- Table A.11
```{r}

hallv1 <- clogit(political ~ credinfo + credcontrol + crednation + dlapse + strata(uid), data = alldata)
summary(hallv1)

h24v1 <- clogit(political ~ credinfo + credcontrol + crednation + dlapse + strata(uid), data = h24data)
summary(h24v1)

h2v1 <- clogit(political ~ credinfo + credcontrol + crednation + dlapse + strata(uid), data = h2data)
summary(h2v1)
#
h05v1 <- clogit(political ~ credinfo + credcontrol + crednation + dlapse + strata(uid), data = h05data)
summary(h05v1)

stargazer(hallv1, h24v1, h2v1, h05v1, type = "text",
          cstar.cutoffs = c(0.05, 0.01, 0.001),
          dep.var.labels   = "Political Post, binary")

```

## Quadratic term of information dissemination on citizen engagement, Table A.12
```{r}
hallv2 <- clogit(political ~ credinfo + I(credinfo^2) + credcontrol + crednation + dlapse + strata(uid), data = alldata)
summary(hallv2)

stargazer(hallv2, type = "text",
          cstar.cutoffs = c(0.05, 0.01, 0.001),
          dep.var.labels   = "Political Post, binary")
```

## Reassruance vs. updates -- Table A.13
```{r}
load("resh24data.RData")

ivh24res <- ivreg(dist2krs ~ credreass | dlapse, data=resh24data)
summary(ivh24res, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24res, resh24data$uid)

```


## Robustness check -- simple linear regression Table A.14
```{r}
# all data
m1 <- lm(dist2krs ~ credinfo, data=alldata)
summary(m1)

m2 <- lm(dist2krs ~ credinfo, data=h24data)
summary(m2)

m3 <- lm(dist2krs ~ credinfo, data=h2data)
summary(m3)

m4 <- lm(dist2krs ~ credinfo, data=h05data)
summary(m4)

stargazer(m1, m2, m3, m4, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          covariate.labels = c("Government information", "Constant"),
          dep.var.labels   = "Distance to the Station (in meters)")
```




## Robustness check -- offwork Table A.15
```{r}
m1v2 <- lm(dist2krs ~ credinfo + offwork, data=alldata)
summary(m1v2)

ivh24v2 <- ivreg(dist2krs ~ credinfo  + offwork | dlapse + offwork, data=h24data)
summary(ivh24v2, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24v2, h24data$uid)

ivh2v2 <- ivreg(dist2krs ~ credinfo  + offwork | dlapse + offwork, data=h2data)
summary(ivh2v2, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh2v2, h2data$uid)

ivh05v2 <- ivreg(dist2krs ~ credinfo  + offwork | dlapse + offwork, data=h05data)
summary(ivh05v2, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh05v2, h05data$uid)

stargazer(m1v2, ivh24v2, ivh2v2, ivh05v2, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          # title = "Information credibility",
          # covariate.labels = c("Official news", "Days past",
          #                      "Off-work", "Constant"),
          dep.var.labels   = "Distance to the Station (in meters)"
          )
```

## Robustness check control other news on the attack -- Table A.16
```{r}
m1v3 <- lm(dist2krs ~ credinfo + credcontrol + crednation, data=alldata)
summary(m1v3)

ivh24v3 <- ivreg(dist2krs ~ credinfo  + credcontrol + crednation | dlapse +  credcontrol + crednation, data=h24data)
summary(ivh24v3, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24v3, h24data$uid)

ivh2v3 <- ivreg(dist2krs ~ credinfo + credcontrol + crednation | dlapse + credcontrol + crednation, data=h2data)
summary(ivh2v3, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh2v3, h2data$uid)

ivh05v3 <- ivreg(dist2krs ~ credinfo + credcontrol + crednation | dlapse + credcontrol + crednation, data=h05data)
summary(ivh05v3, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh05v3, h05data$uid)

stargazer(m1v3, ivh24v3, ivh2v3, ivh05v3, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          # title = "Information credibility",
          covariate.labels = c("Government information", "Assertion of control",
                               "Sensational stories for inciting nationalism", "Constant"),
          dep.var.labels   = "Distance to the Station (in meters)"
          )
```


## Robustness check -- Table A.17
```{r}
m1v4 <- lm(dist2krs ~ credinfo + follower + following, data=alldata)
summary(m1v4)

ivh24v4 <- ivreg(dist2krs ~ credinfo + follower + following | dlapse + follower + following, data=h24data)
summary(ivh24v4, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24v4, h24data$uid)

ivh2v4 <- ivreg(dist2krs ~ credinfo + follower + following | dlapse + follower + following, data=h2data)
summary(ivh2v4, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh2v4, h2data$uid)

ivh05v4 <- ivreg(dist2krs ~ credinfo + follower + following | dlapse + follower + following, data=h05data)
summary(ivh05v4, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh05v4, h05data$uid)

stargazer(m1v4, ivh24v4, ivh2v4, ivh05v4, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          # title = "Information credibility",
          covariate.labels = c("Government information", "Number of follower",
                               "Number of following", "Constant"),
          dep.var.labels   = "Distance to the Station (in meters)"
          )
```


## Security check at the station after the attack Table A.18
```{r}
m1v5 <- lm(dist2krs ~ credinfo + uaft, data=alldata)
summary(m1v5)

ivh24v5 <- ivreg(dist2krs ~ credinfo  + uaft | dlapse + uaft, data=h24data)
summary(ivh24v5, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24v5, h24data$uid)

ivh2v5 <- ivreg(dist2krs ~ credinfo  + uaft | dlapse + uaft, data=h2data)
summary(ivh2v5, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh2v5, h2data$uid)

ivh05v5 <- ivreg(dist2krs ~ credinfo  + uaft | dlapse + uaft, data=h05data)
summary(ivh05v5, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh05v5, h05data$uid)

stargazer(m1v5, ivh24v5, ivh2v5, ivh05v5, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          # title = "Information credibility",
          covariate.labels = c("Government information", "Users at the Station after the Attack",
                                "Constant"),
          dep.var.labels   = "Distance to the Station (in meters)"
          )
```

## Restaurants and shops at the station before the attack - Table A. 19
```{r}
m1v6 <- lm(dist2krs ~ credinfo + ub4, data=alldata)
summary(m1v6)

ivh24v6 <- ivreg(dist2krs ~ credinfo  + ub4 | dlapse + ub4, data=h24data)
summary(ivh24v6, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24v6, h24data$uid)

ivh2v6 <- ivreg(dist2krs ~ credinfo  + ub4 | dlapse + ub4, data=h2data)
summary(ivh2v6, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh2v6, h2data$uid)

ivh05v6 <- ivreg(dist2krs ~ credinfo  + ub4 | dlapse + ub4, data=h05data)
summary(ivh05v6, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh05v6, h05data$uid)

stargazer(m1v6, ivh24v6, ivh2v6, ivh05v6, type="text",star.cutoffs = c(0.05, 0.01, 0.001),
          # title = "Information credibility",
          covariate.labels = c("Government information", "Users at the Station before the Attack",
                                "Constant"),
          dep.var.labels   = "Distance to the Station (in meters)"
          )
```




## Tencent news -- Table A.20
```{r}
load("qqh24data.Rdata")

ivh24qq <- ivreg(dist2krs ~ oqq | dlapse, data=qqh24data)
summary(ivh24qq, vcov = sandwich, df = Inf, diagnostics = TRUE)
cluster.robust.se(ivh24qq, qqh24data$uid)

```





